package site.teamo.biu.flink.web.command;

import cn.hutool.core.util.RuntimeUtil;

import java.io.File;

/**
 * @author haocongshun
 * @date 2023/07/28 11:13:18
 */
public class JavaProcess {

    private final String command;

    public JavaProcess(String[] classPath, String mainClass, String[] args) {
        String java = "java";
        String cp = "-cp " + String.join(File.pathSeparator, classPath);
        String parameters = String.join(" ", args);
        this.command = String.join(" ", new String[]{java, cp, mainClass, parameters});
    }

    public String exec() {
        return RuntimeUtil.execForStr(command);
    }


    public static void main(String[] args) throws Exception {
        JavaProcess javaProcess = new JavaProcess(
                new String[]{
                        "D:\\workspace\\personal\\biu-flink\\biu-flink-sdk\\target\\biu-flink-sdk-1.0-SNAPSHOT-jar-with-dependencies.jar",
                        "D:\\workspace\\personal\\biu-flink\\biu-flink-tool\\target\\biu-flink-tool-1.0-SNAPSHOT-jar-with-dependencies.jar",
                        "D:\\workspace\\personal\\biu-flink\\biu-flink-function\\target\\biu-flink-function-1.0-SNAPSHOT.jar"
                },
                "site.teamo.biu.flink.tool.BiuFlinkToolScanFunction",
                new String[]{"site.teamo.biu.flink.function"});
        System.out.println(javaProcess.exec());
    }
}
